<template>
  <div>
    <table
      border="1"
      width="700"
      style="border-collapse: collapse"
    >
      <caption>
        购物车
      </caption>
      <thead>
        <tr>
          <th>
            <input v-model="flag" type="checkbox" /> <span>全选</span>
          </th>
          <th>名称</th>
          <th>价格</th>
          <th>数量</th>
          <th>总价</th>
          <th>操作</th>
        </tr>
      </thead>
      <my-table />
      <tfoot>
        <tr>
          <td>合计:</td>
          <td colspan="5">
            {{ totalPrice }}
          </td>
        </tr>
      </tfoot>
    </table>
    <input v-model.trim="form.name" type="text"> 商品名称
    <input v-model.number="form.price" type="text"> 商品价格
    <input v-model.number="form.num" type="text"> 商品数量
    <button @click="onClick">点击提交</button>
  </div>
</template>

<script>
import { mapState, mapMutations, mapGetters } from 'vuex'
import MyTable from './components/MyTable.vue'
export default {
  components: { MyTable },
  data () {
    return {
      form: {
        name: '',
        price: '',
        num: '',
        checked: false
      }
    }
  },
  computed: {
    ...mapState(['goodList']),
    ...mapGetters(['getAll', 'totalPrice']),
    flag: {
      get () {
        return this.getAll
      },
      set (val) {
        this.setAll(val)
      }
    }
  },
  methods: {
    ...mapMutations(['setAll', 'addNewList']),
    onClick () {
      this.addNewList(this.form)
    }

  }
}
</script>

<style>
</style>
